package com.bubbleby.social.launch.client;

/**
 * The Class Browser.
 * Checks the browser
 */
public class Browser {

	public static final int					OPERA		= 0;
	
	public static final int					IE			= 1;
	
	public static final int					IE6			= 2;
	
	public static final int					IE8			= 3;
	
	public static final int					IE9			= 3;
	
	public static final int					IE7			= 4;
	
	public static final int					WEBKIT		= 5;
	
	public static final int					IPHONE		= 6;
	
	public static final int					CHROME		= 7;
	
	public static final int					SAFARI		= 8;
	
	public static final int					KONQUEROR	= 9;
	
	public static final int					KONQUEROR4	= 10;
	
	public static final int					GECKO		= 11;
	
	public static final int					GECKO19		= 12;
	
	public static final int					UNKNOWN		= 13;
	
	public static final int					IPAD		= 14;
	
	/** The browser constant */
	private int browser = -1;
	
	/** Old ie browser. */
	private boolean						isOldIE							= false;
	
	/** The browser instance. */
	private static Browser instance;
	
	/**
	 * Instantiates a new browser.
	 */
	private Browser() {
		browser = evalBrowser();
		if (browser==IE6||browser==IE7||browser==IE8) isOldIE=true;
	}
	
	/**
	 * Gets the single instance of Browser.
	 *
	 * @return single instance of Browser
	 */
	public static Browser getInstance() {
		if (instance==null) 
			instance=new Browser();
		return instance;
	}
	
	/**
	 * Gets the browser.
	 *
	 * @return the browser
	 */
	public int getBrowser() {
		return browser;
	}
	
	/**
	 * Checks whether is old ie.
	 *
	 * @return true, if is old ie
	 */
	public boolean isOldIE() {
		return isOldIE;
	}
	
	
	/**
	 * Eval browser.
	 *
	 * @return the int
	 */
	private native int evalBrowser() /*-{
	var browser = @com.bubbleby.social.launch.client.Browser::UNKNOWN;

	if (navigator.userAgent.match(/iPad/i) != null)  browser = @com.bubbleby.social.launch.client.Browser::IPAD;
	else if (window.opera) browser = @com.bubbleby.social.launch.client.Browser::OPERA;
	else if(document.all) {	
		browser = @com.bubbleby.social.launch.client.Browser::IE7;
		if(typeof(window.XMLHttpRequest) == "undefined") browser = @com.bubbleby.social.launch.client.Browser::IE6;
		if(typeof(document.querySelectorAll) != "undefined") browser = @com.bubbleby.social.launch.client.Browser::IE8;
		if(navigator.userAgent.indexOf("MSIE 9.0")>-1) browser = @com.bubbleby.social.launch.client.Browser::IE9;
	} 
	else if (/iPhone|iPod/i.test(navigator.userAgent)) browser = @com.bubbleby.social.launch.client.Browser::IPHONE;
	else if (/Chrome/i.test(navigator.userAgent)) browser = @com.bubbleby.social.launch.client.Browser::CHROME;
	else if (/Safari/i.test(navigator.userAgent)) browser = @com.bubbleby.social.launch.client.Browser::SAFARI;
	else if (/WebKit/i.test(navigator.userAgent)) browser = @com.bubbleby.social.launch.client.Browser::WEBKIT;
	

	else if(navigator.vendor == "KDE" && /native code/.test(document.getElementsByClassName)) browser = @com.bubbleby.social.launch.client.Browser::KONQUEROR4;
	else if(navigator.vendor == "KDE") browser = @com.bubbleby.social.launch.client.Browser::KONQUEROR;
	else if(navigator.product == "Gecko" && Array.reduce) browser = @com.bubbleby.social.launch.client.Browser::GECKO;
	else if(navigator.product == "Gecko") browser = @com.bubbleby.social.launch.client.Browser::GECKO19;

	return browser;
}-*/;

}
